import upperFirst from 'lodash/upperFirst'
import camelCase from 'lodash/camelCase'

export default {
  install(app) {
    //   eagger:返回的对象会包含匹配模式的所有文件，并且会立即进行加载和执行 动态导入
    const baseComponent = import.meta.glob('../components/base/*.vue', { eager: true })
    Object.entries(baseComponent).forEach(([path, module]) => {
      const componentName = upperFirst(
        camelCase(
          camelCase(
            path
              .split('/')
              .pop()
              .replace(/\.\w+$/, '')
          )
        )
      )

      // export default
      app.component(`Base${componentName}`, module.default)
    })
  }
}
